home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / LEnhancedEditField / LEnhancedEditField.cp next >
Encoding:
Text File  |  1996-09-14  |  6.6 KB  |  227 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    File:                LEnhancedEditField.cp
  3. //    Version:            1.0 - Feb 08,1996
  4. //    Author:            Mike Shields (mshields@inconnect.com)
  5. //
  6. //    Copyright ©1996 Mike Shields. All rights reserved.
  7. //    I hereby grant users of LEnhancedEditField permission to use it (or any modified 
  8. //    version of it) in applications (or any other type of Macintosh software 
  9. //    like extensions -- freeware, shareware, commercial, or other) for free, 
  10. //    subject to the terms that:
  11. //
  12. //        (1)  This agreement is non-exclusive.
  13. //
  14. //        (2)  I, Mike Shields, retain the copyright to the original source code.
  15. //
  16. //    These two items are the only required conditions for use. However, I do have 
  17. //    an additional request. Note, however, that this is only a request, and 
  18. //    that it is not a required condition for use of this code.
  19. //
  20. //        (1) That I be given credit for LEnhancedEditField code in the copyrights or 
  21. //            acknowledgements section of your manual or other appropriate documentation.
  22. //
  23. //
  24. //    I would like to repeat that this last item is only a request. You are prefectly 
  25. //    free to choose not to do any or all of them.
  26. //    
  27. //        This source code is distributed in the hope that it will be useful,
  28. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. // ===========================================================================
  31. //    LEnhancedEditField.h        <- double-click + Command-D to see class declaration
  32. //
  33. //
  34. // LEditField which properly dims itself when disabled
  35. #include "LEnhancedEditField.h"
  36.  
  37. #include <LStream.h>
  38. #include <UDrawingState.h>
  39. #include <UDrawingUtils.h>
  40.  
  41. #ifndef __QUICKDRAW__
  42. #include <Quickdraw.h>
  43. #endif
  44. // ---------------------------------------------------------------------------
  45. //        • CreateEditFieldStream
  46. // ---------------------------------------------------------------------------
  47. //    Create a new EditField object from the data in a Stream
  48.  
  49. LEnhancedEditField*
  50. LEnhancedEditField::CreateEditFieldStream(LStream *inStream)
  51. {
  52.     return (new LEnhancedEditField(inStream));
  53. }
  54.  
  55.  
  56. // ---------------------------------------------------------------------------
  57. //        • LEnhancedEditField
  58. // ---------------------------------------------------------------------------
  59. //    Default Constructor
  60.  
  61. LEnhancedEditField::LEnhancedEditField()
  62. {
  63. }
  64.  
  65.  
  66. // ---------------------------------------------------------------------------
  67. //        • LEnhancedEditField(LEnhancedEditField&)
  68. // ---------------------------------------------------------------------------
  69. //    Copy Constructor
  70.  
  71. LEnhancedEditField::LEnhancedEditField(
  72.     const LEnhancedEditField &inOriginal)
  73.         : LEditField(inOriginal)
  74. {
  75. }
  76.  
  77.  
  78. // ---------------------------------------------------------------------------
  79. //        • LEnhancedEditField
  80. // ---------------------------------------------------------------------------
  81. //    Construct from input parameters
  82.  
  83. LEnhancedEditField::LEnhancedEditField(
  84.     const SPaneInfo    &inPaneInfo,
  85.     Str255                inString,
  86.     ResIDT                inTextTraitsID,
  87.     Int16                    inMaxChars,
  88.     Boolean                inHasBox,
  89.     Boolean                inHasWordWrap,
  90.     KeyFilterFunc        inKeyFilter,
  91.     LCommander            *inSuper)
  92.         : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, 
  93.                         inHasBox, inHasWordWrap, inKeyFilter, inSuper)
  94. {
  95. }
  96.  
  97.  
  98. LEnhancedEditField::LEnhancedEditField(
  99.     const SPaneInfo    &inPaneInfo,
  100.     Str255                inString,
  101.     ResIDT                inTextTraitsID,
  102.     Int16                    inMaxChars,
  103.     Uint8                    inAttributes,
  104.     KeyFilterFunc        inKeyFilter,
  105.     LCommander            *inSuper)
  106.         : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inAttributes, 
  107.                     inKeyFilter, inSuper)
  108. {
  109. }
  110.  
  111.  
  112. // ---------------------------------------------------------------------------
  113. //        • LEnhancedEditField(LStream*)
  114. // ---------------------------------------------------------------------------
  115. //    Construct an EditField from the data in a Stream
  116.  
  117. LEnhancedEditField::LEnhancedEditField(
  118.     LStream    *inStream)
  119.         : LEditField(inStream)
  120. {
  121. }
  122.  
  123.  
  124. // ---------------------------------------------------------------------------
  125. //        • ~LEnhancedEditField
  126. // ---------------------------------------------------------------------------
  127. //    Destructor
  128.  
  129. LEnhancedEditField::~LEnhancedEditField()
  130. {
  131. }
  132.  
  133. // ---------------------------------------------------------------------------
  134. //        • DrawBox
  135. // ---------------------------------------------------------------------------
  136. //    Draw box around an EditField. Overidden to NOT draw in grey patern when disabled.
  137.  
  138. void
  139. LEnhancedEditField::DrawBox()
  140. {
  141.     // Box around an EditField is outset from the Text by 2 pixels.
  142.     // The box itself is 1 pixel thick, drawn in the foreground color
  143.     // of the Pane (not necessarily the same as the text color). 
  144.     //
  145.     // The 1 pixel rectangle between the box and the text draws in
  146.     // the background color of the text.
  147.     StColorState    saveColors;            // Preserve color state
  148.     Rect                frame;
  149.     CalcLocalFrameRect(frame);
  150.     ::PenNormal();
  151.     
  152.     // Draw empty area between Box and Text. On entry, the fore
  153.     // and back colors for the Text are in effect (as set in FocusDraw).
  154.     // Use Text back color as the fore color for the empty area.
  155.     ::InsetRect(&frame, 1, 1);
  156.     RGBColor    emptyColor;
  157.     ::GetBackColor(&emptyColor);
  158.     ::RGBForeColor(&emptyColor);
  159.     ::FrameRect(&frame);
  160.     
  161.     // Draw border around EditField
  162.     ::InsetRect(&frame, -1, -1);
  163.     
  164.     ApplyForeAndBackColors();
  165.     ::FrameRect(&frame);
  166. }
  167.  
  168. // ---------------------------------------------------------------------------
  169. //        • DrawSelf
  170. // ---------------------------------------------------------------------------
  171. //    Draw an EditField
  172.  
  173. void
  174. LEnhancedEditField::DrawSelf()
  175. {
  176.     // draw ourseleves like normal, 
  177.     LEditField::DrawSelf();
  178.     
  179.     // now paint over ourselves to make ourselves reflect our
  180.     // disabled-ness.
  181.     if ( mEnabled != triState_On )
  182.     {
  183.         Rect            frame;
  184.         CalcLocalFrameRect(frame);
  185.         
  186.         StDeviceLoop    theLoop(frame);
  187.         Int16                depth;
  188.  
  189.         while ( theLoop.NextDepth(depth) )
  190.         {
  191.             if (depth >= 4)
  192.             {
  193.                 PaintDisabled(&frame);
  194.             }
  195.             else
  196.             {
  197.                 StColorPenState        savedPenState;    
  198.                 
  199.                 PenMode(patBic);
  200.                 PenPat(&qd.gray);
  201.                 PaintRect(&frame);
  202.             }
  203.         }
  204.     }
  205. }
  206.  
  207. // ---------------------------------------------------------------------------
  208. //        • PaintDisabled
  209. // ---------------------------------------------------------------------------
  210. //    Paint over ourselves with the proper settings to "grey out" our previous drawing.
  211. void LEnhancedEditField::PaintDisabled(Rect *inDrawRect)
  212. {
  213.     StColorPenState    savedPenState;
  214.     RGBColor                newRGBColor, 
  215.                             newOpColor;
  216.     
  217.     newOpColor.red = newOpColor.blue = newOpColor.green = 0x7530;
  218.     newRGBColor.red = newRGBColor.blue = newRGBColor.green = 0xFFFF;
  219.     
  220.     ::OpColor(&newOpColor);
  221.     ::RGBForeColor(&newRGBColor);
  222.     ::PenMode(blend);
  223.     ::PenPat(&qd.black);
  224.     ::PaintRect(inDrawRect);
  225. }
  226.  
  227.